package demo2;

import java.util.Scanner;

class Admin{
    String name ;
    String passWord ;

    public Admin(String name, String passWord) {
        this.name = name;
        this.passWord = passWord;
    }
}
public class Test1 {
    public static void func(Admin admin) throws NameException,PassWordException{
        if(!admin.name.equals("张三")){
            throw new NameException("用户名错误") ;
        }else if(!admin.passWord.equals("123456")){
            throw new PassWordException("密码错误") ;
        }
        System.out.println("登录成功");
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in) ;

        System.out.println("请输入你的用户名");
        String name = scan.nextLine() ;
        System.out.println("请输入密码");
        String passWord = scan.nextLine() ;
        Admin admin = new Admin(name,passWord) ;
      try{
          func(admin);
      }catch (NameException e){
          e.printStackTrace();
          System.out.println("名字错误异常");
      }catch (PassWordException e){
          e.printStackTrace();
          System.out.println("密码错误异常");
      }finally {
          System.out.println("回收资源");
          scan.close();
      }

    }

}

